
//
//  TweetCommentTableViewCell.m
//  OSChina
//
//  Created by 8b410-2 on 17/1/1.
//  Copyright © 2017年 abb. All rights reserved.
//

#import "OSCTweetCommentTableViewCell.h"
#import "UILabel+Common.h"
#import "UIButton+Common.h"
#import "UIImageView+SDWebImage.h"
@interface OSCTweetCommentTableViewCell ()
/// 昵称Label
@property (nonatomic, strong) UILabel *nameLabel;
/// 时间Label
@property (nonatomic, strong) UILabel *timeLabel;
/// 评论正文Label
@property (nonatomic, strong) UILabel *contentLabel;
/// 头像view
@property (nonatomic, strong) UIImageView *iconView;
/// 回复Button
@property (nonatomic, strong) UIButton *replyButton;

@end

@implementation OSCTweetCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    _nameLabel = [UILabel labelWithSystemFontSize:15 textColor:[UIColor blackColor]];
    [self.contentView addSubview:_nameLabel];
    _timeLabel = [UILabel labelWithSystemFontSize:10 textColor:[UIColor colorWithHexString:@"9D9D9D"]];
    [self.contentView addSubview:_timeLabel];
    _contentLabel = [UILabel labelWithSystemFontSize:14 textColor:[UIColor blackColor]];
    [_contentLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    _contentLabel.preferredMaxLayoutWidth = kScreen_Width - 8 - 32 - 8 - 8;
    [self.contentView addSubview:_contentLabel];
    _iconView = [UIImageView new];
    [self.contentView addSubview:_iconView];
    _replyButton = [UIButton buttonWithImageNameStr:@"ic_comment_30" BackgroundColor:nil];
    [self.contentView addSubview:_replyButton];
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(32, 32));
        make.top.equalTo(self.contentView).offset(8);
        make.left.equalTo(self.contentView).offset(8);
    }];
    [_replyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(17);
        make.right.equalTo(self.contentView).offset(-8);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(8);
        make.top.equalTo(self.iconView);
        make.right.lessThanOrEqualTo(self.replyButton.mas_left).offset(-8);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(3);
        make.right.lessThanOrEqualTo(self.nameLabel);
        make.left.equalTo(self.nameLabel);
    }];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.right.lessThanOrEqualTo(self.replyButton.mas_right);
        make.top.equalTo(self.timeLabel.mas_bottom).offset(3);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
}

- (void)bindViewModel:(id)viewModel {
    self.viewModel = viewModel;
}

- (void)setViewModel:(OSCTweetCommentViewModel *)viewModel {
    _viewModel = viewModel;
    [_iconView abb_loadImageWithUrlStr:viewModel.commentPortrait PlaceHolderImageStr:userDefaultImageStr Radius:16];
    [_nameLabel setText:viewModel.commentAuthor];
    [_timeLabel setText:viewModel.pubDate];
    [_contentLabel setAttributedText:viewModel.content];
}
@end
